package com.lee.demo.ui.activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
/**
 * 拍照和相册选择图片的Demo
 */
import androidx.appcompat.app.AppCompatActivity;

import com.lee.demo.R;

import java.io.File;

import cn.lee.cplibrary.util.LogUtil;
import cn.lee.cplibrary.util.SharedPreferencesUtils;
import cn.lee.cplibrary.util.takephotos.ImageUtils;
import cn.lee.cplibrary.util.takephotos.PhotoUtil;
import cn.lee.cplibrary.util.timer.TimeUtils;

public class PhotoActivity extends AppCompatActivity {
    private ImageView imageView;
    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo);
        PhotoUtil.init(this, savedInstanceState);
        imageView = (ImageView) findViewById(R.id.imageView);
        PhotoUtil.colorCancel= Color.parseColor("#aa738ffe");

        findViewById(R.id.btn1).setOnClickListener(v -> PhotoUtil.showPicChooseDialog(PhotoActivity.this,null));
        findViewById(R.id.btn_camera).setOnClickListener(v -> PhotoUtil.gotoCarema(PhotoActivity.this, null));
        findViewById(R.id.btn_photo).setOnClickListener(v -> PhotoUtil.gotoPhoto(PhotoActivity.this, null));
        textView = (TextView) findViewById(R.id.textView);
        SharedPreferencesUtils.putShareValue(this,"user","李翠侠");
        textView.setText( SharedPreferencesUtils.getShareString(this,"user"));

        LogUtil.i("",this,"1111111111111111111111111");
        PhotoUtil.setQuality(400);
        PhotoUtil.setDesWidth(1200f);
        PhotoUtil.setOnlyUseSystemCamera(true);
        PhotoUtil.isShowGuideDialog= true;
        LogUtil.i("","PhotoUtil="+ ImageUtils.getQuality()+",,"+ImageUtils.getDesWidth());
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        File file = PhotoUtil.getImageFile(this, requestCode, resultCode, data, String.valueOf(TimeUtils.getCurTimeMillis()));
        try {
            Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
            imageView.setImageBitmap(bitmap);
            LogUtil.i("","PhotoUtil00000000----="+ ImageUtils.getQuality()+",,"+ImageUtils.getDesWidth());
        }catch (NullPointerException e){

        }
    }

}
